package wnxy.wn44.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import wnxy.wn44.mapper.PoetryMapper;
import wnxy.wn44.model.Poetry;
import wnxy.wn44.service.bo.PoetryQueryParam;

import java.util.Arrays;
import java.util.List;

@Service
public class PoetryServiceImpl implements PoetryService{

    private PoetryMapper poetryMapper;

    @Autowired
    public void setPoetryMapper(PoetryMapper poetryMapper) {
        this.poetryMapper = poetryMapper;
    }

    @Override
    public Poetry findPoetryById(Integer id){
        Poetry poetry = poetryMapper.selectByPrimaryKey(id);
        return poetry;
    }

    @Override
    public PageInfo<Poetry> listByPage(PoetryQueryParam queryParam) {
        PageHelper.startPage(queryParam.getPageNum(),queryParam.getPageSize());
        List<Poetry> poetryList = poetryMapper.selectAllByCondition(queryParam);
        PageInfo<Poetry> pageInfo = new PageInfo<>(poetryList);
        return pageInfo;
    }

    @Override
    public int delById(Integer... ids) {
        return poetryMapper.delById(Arrays.asList(ids));
    }


}